package tanke;

public class Shot implements Runnable {

	private int x;
	private int y;
	private int direct;
	private int speed = 3;
	private boolean isLive = true;

	public Shot(int x, int y,int direct) {
		this.x = x;
		this.y = y;
		this.direct = direct;
	}

	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}
	public int getSpeed() {
		return speed;
	}
	public void setSpeed(int speed) {
		this.speed = speed;
	}

	public int getDirect() {
		return direct;
	}
	public void setDirect(int direct) {
		this.direct = direct;
	}

	public boolean isLive() {
		return isLive;
	}
	public void setLive(boolean isLive) {
		this.isLive = isLive;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		while(true)
		{
			try {
				Thread.sleep(50);
			} catch (Exception e) {
				// TODO: handle exception
			}

			switch(direct) {
				case 1:
					//上
					y-=speed;
					break;
				case 2:
					y+=speed;
					break;
				case 3:
					x-=speed;
					break;
				case 4:
					x+=speed;
					break;
			}

			//System.out.println("子弹坐标x="+x+" y="+y);
			//子弹何时死亡???

			//判断该子弹是否碰到边缘.
			if(x<0||x>400||y<0||y>300)
			{
				this.isLive=false;
				break;
			}
			if(this.isLive == false){
				break;
			}
		}
	}

}
